//
// Created by LUOJIARUI on 2021/4/26.
//

#ifndef HNSW_HNSW_LOUVAIN_H
#define HNSW_HNSW_LOUVAIN_H

#endif //HNSW_HNSW_LOUVAIN_H
#include "graph_binary.h"
#include "community.h"
#include <queue>
#include <cmath>
#include <hash_set>
typedef pair<int, float> myPair;
struct ComparatorForMaxHeap {
    bool operator()(myPair p1, myPair p2) {
        return p1.second < p2.second;
    }
};
struct ComparatorForMinHeap {
    bool operator()(myPair p1, myPair p2) {
        return p1.second > p2.second;
    }
};

vector<vector<int>> &scc(Graph &G, vector<vector<int>> &SCCG);
vector<vector<pair<int, vector<int>>>> &louvainPlus(Community &c, vector<vector<pair<int, vector<int>>>> &partit,
                                                    vector<vector<int>> &linksInLayer,
                                                    vector<vector<float>> &weightInLayer,
                                                    vector<vector<long>> &degreeInLayer,
                                                    vector<vector<pair<int,int>>>& up2bottom);

class HNSW_Louvain{
public:
    float* data;
    int nd;
    int d;
    vector<vector<vector<int>>> ls;
    vector<vector<vector<long>>> ds;
    vector<vector<vector<float>>> ws;
    vector<vector<vector<pair<int,int>>>> up2bottom;
    vector<vector<vector<pair<int, vector<int>>>>> partitions;
    vector<long> degree;
    vector<int> links;
    vector<float> weight;
    HNSW_Louvain();
    HNSW_Louvain(float* data,int d,int nd,long m,vector<long> degree,vector<int> links,vector<float> weight);
    myPair searchUpperLayer(int selectSCC,int layerNum,myPair ep,float* queryPos);
    priority_queue<myPair,vector<myPair>,ComparatorForMaxHeap>
    searchBaseLayer(int k1,int ef,myPair epPair,float* query);
    priority_queue<myPair,vector<myPair>,ComparatorForMaxHeap> knn(float* queryPos,int k1,int ef);
    float dis(const float* data1,const float* data2);
};